
	// base info 基本信息
	var BI = {
		// 注销图书信息
		logout: {
			id 	 : '#logout-dg',
			name : 'logout',
			url  : {query: 'logoutBookReport/list'},
			toolbar : {id: '#logout-tb'},
		},
	};
	// 读者表格对象
	BI.logout.obj 	 = new easyUI.extend.TABLE(BI.logout.name, BI.logout.url);

	// 随机颜色生产器
	var randomColorFactor = function() {
	    return Math.round(Math.random() * 255);
   	};
    var randomColor = function(opacity) {
        return 'rgba(' + randomColorFactor() + ',' + randomColorFactor() + ',' + randomColorFactor() + ',' + (opacity || '.3') + ')';
    };
    // 获得所有颜色
	var getColors = function(length){
		var colors = [];
		for (var i = 0; i <= length - 1; i++){
			colors.push(randomColor());
		}
		
		return colors;
	}
	
	// 图形配置属性
	var doughnutConfig = {
        type: 'pie',
        data: {
        	datasets: [{
                data: [],
                backgroundColor: [],
            }],
            labels: []
        },
        options: {
            responsive: true,
            legend: {
                position: 'top',
            },
            title: {
                display: true,
                text: '注销图书分析图表'
            },
            animation: {
                animateScale: true,
                animateRotate: true
            }
        }
    };	
		
	var flage = false;

	$(document).ready(function(){
			
		var doughnutContext = document.getElementById("logoutDoughnutChart").getContext("2d");
		window.doughnutChart = new Chart(doughnutContext, doughnutConfig);
		
		// 初始化datagrid
		$(BI.logout.id).datagrid({ 
	        striped: true,
	        rownumbers: true,
	        pageSize: 10,
	        idField: 'Id', //这个idField必须指定为输出的id，输出的是Id就必须是Id，不能小写
	        sortName: 'Id',
	        sortOrder: 'desc',
	        width: '100%', //宽度
	        height: 400, //高度
	        url: BI.logout.url.query, //请求路径
	        singleSelect: true, //单选
	        fitColumns: true, //设置为true将自动使列适应表格宽度以防止出现水平滚动。
	        pagination: true, //启用分页
	        checkOnSelect: false,
	        selectOnCheck: false,
			resizable: false,
			
	        columns: [
	            [
	                { field: 'id', title:'编号', align:'center', width: 70, hidden: true},
	                { field: 'name', title:'书名', align:'center', width: 70},
	                { field: 'publishDate', title:'出版日期', align:'center', width: 70},
	                { field: 'ISBN', title:'书码', align:'center', width: 70},
	                { field: 'num', title:'数量', align:'center', width: 100},
	            ]
	        ],
	        
	        onLoadSuccess: function(data){
	        	var labels = [], num = [];
	        	$.each(data.rows, function(index, one) {
	        		labels.push(one.name);
	        		num.push(one.num);
	        	});
	        	doughnutConfig.data.datasets[0].data = num;
	        	doughnutConfig.data.labels = labels;
	        	doughnutConfig.data.datasets[0].backgroundColor = getColors(labels.length);
	        },
	               
	        toolbar: $(BI.logout.toolbar.id),
	    });
	    
	    // 视图切换事件
		$('#change-view')[0].addEventListener('click', function(e){
			if (!flage){
				$('.panel.datagrid.easyui-fluid').css('margin-right', -100 + '%');
				$('.chart-view').css('opacity', 1);
				doughnutChart.update();
				flage = !flage;
			} else{
				$('.panel.datagrid.easyui-fluid').css('margin-right', 0 + '%');
				$('.chart-view').css('opacity', 0);
				flage = !flage;
			}
		}, false);
	});
	
